package com.ssm.gbq.controller;

import com.ssm.gbq.mapper.DoctorCategoryMapper;
import com.ssm.gbq.model.DoctorCategory;
import com.ssm.gbq.service.DoctorCategoryService;
import gbq.ssm.utils.PageBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

@Controller
@RequestMapping("/doctorCategory")
public class DoctorCategoryController {

    @Autowired
    private DoctorCategoryService doctorCategoryService;

    @Autowired
    private DoctorCategoryMapper doctorCategoryMapper;

    @ResponseBody
    @RequestMapping(value = "/openDoctorCategoryTable", method = RequestMethod.POST)
    public HashMap<String, Object> openDoctorCategoryTable(String type, int pageSize, int currentPage) {
        HashMap<String, Object> result = new HashMap<String, Object>();
        PageBounds<DoctorCategory> pageBounds = null;
        try {
            pageBounds = doctorCategoryService.openDoctorCategoryTable(type, currentPage, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (type != null && type != "") {
            result.put("count", pageBounds.getPageList().size());
        } else {
            result.put("count", doctorCategoryMapper.Count());
        }
        result.put("data", pageBounds);
        return result;
    }

    /**
     * 获取全部信息
     */
    @ResponseBody
    @RequestMapping(value = "/selectAllDoctorCategory", method = RequestMethod.POST)
    public HashMap<String, Object> selectAllDoctorCategory() {
        HashMap<String, Object> result = new HashMap<String, Object>();
        List<DoctorCategory> doctorCategory = doctorCategoryService.selectAllDoctorCategory();
        result.put("data", doctorCategory);
        return result;
    }

    /**
     * 添加
     */
    @ResponseBody
    @RequestMapping(value = "/addDoctorCategory", method = RequestMethod.POST)
    public HashMap<String, Object> addDoctorCategory(DoctorCategory doctorCategory) {
        HashMap<String, Object> result = new HashMap<String, Object>();
        doctorCategoryService.addDoctorCategory(doctorCategory);
        return result;
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping(value = "/updateDoctorCategory", method = RequestMethod.POST)
    public HashMap<String, Object> updateDoctor(DoctorCategory doctorCategory) {
        HashMap<String, Object> result = new HashMap<String, Object>();
        doctorCategoryService.updateDoctorCategory(doctorCategory);
        return result;
    }

    /**
     * 通过id删除
     */
    @ResponseBody
    @RequestMapping(value = "/deleteDoctorCategoryById", method = RequestMethod.POST)
    public HashMap<String, Object> deleteDoctorCategoryById(Integer id) {
        HashMap<String, Object> result = new HashMap<String, Object>();
        doctorCategoryService.deleteDoctorCategoryById(id);
        return result;
    }

    /**
     * 通过id多删除
     *
     * @param @return
     * @Title: delStudentById
     */
    @ResponseBody
    @RequestMapping(value = "/deleteDoctorCategoryByIds", method = RequestMethod.POST)
    public HashMap<String, Object> deleteDoctorCategoryByIds(Integer[] ids) {
        HashMap<String, Object> result = new HashMap<String, Object>();
        doctorCategoryService.deleteDoctorCategoryByIds(Arrays.asList(ids));
        return result;
    }
}
